"""计算图像有效区域"""


def top(img):
    for r in range(100):
        for c in range(img.shape[1]):
            if img[r, c] != 0:
                return r


def bottom(img):
    for r in range(img.shape[0]-1, 400, -1):
        for c in range(img.shape[1]):
            if img[r, c] != 0:
                return r


def left(img):
    for c in range(100):
        for r in range(img.shape[0]):
            if img[r, c] != 0:
                return c


def right(img):
    for c in range(img.shape[1]-1, 550, -1):
        for r in range(img.shape[0]):
            if img[r, c] != 0:
                return c
